<ol class="breadcrumb">
    <li><a href="#">奇妙云箱</a></li>
    <li>箱子管理</li>
</ol>
<div class="panel panel-default">
    <div class="panel-heading">
        <span class="glyphicon glyphicon-list"></span>
        <span class="panel-title">箱子列表</span>
        <% if(session.permissionMap[1000]){ %>
        <a href="/box/create" class="pull-right btn btn-success btn-sm" style="margin-top: -3px;">
            <span class="glyphicon glyphicon-plus"></span>
            <span>新增</span>
        </a>
        <% } %>
    </div>
    <div class="table-responsive">
        <table class="table table-hover table-striped">
            <thead>
            <tr>
                <th>箱子ID</th>
                <th>控制器订阅号</th>
                <th>箱子布局</th>
                <th>一般中奖率</th>
                <th>高中奖率</th>
                <th>高中奖率时段</th>
                <th>箱子操作</th>
            </tr>
            </thead>
            <tfoot>
            <tr>
                <td colspan="7">
                    <nav class="twbsPagination"></nav>
                </td>
            </tr>
            </tfoot>
            <tbody>
            <% for(var i = 0;i < datas.length;i++){ %>
            <tr>
                <td><a href="/box_management/box_order?boxid=<%= datas[i].box_id %>"><%= datas[i].box_id %></a></td>
                <td><%= datas[i].sim %></td>
                <td><%= datas[i].box_layout %></td>
                <td><%= datas[i].probability1 %></td>
                <td><%= datas[i].probability %></td>
                <td><%= datas[i].happy_times %></td>
                <td>
                    <% if(session.permissionMap[1003]){ %>
                    <a class="btn btn-default btn-sm"
                       href="/box/doors?boxid=<%= datas[i].box_id %>&&index=0">箱门状态</a>
                    <% } %>
                    <% if(session.permissionMap[1004]){ %>
                    <a class="btn btn-default btn-sm" href="/box/active/list?num=1&boxid=<%= datas[i].box_id %>">活动管理</a>
                    <% } %>
                    <% if(session.permissionMap[1005]){ %>
                    <!--<a class="btn btn-default btn-sm" href="/box/prize/list?boxid=<%= datas[i].box_id %>">奖品设置</a>-->
                    <% } %>
                    <% if(session.permissionMap[1006]){ %>
                    <a class="btn btn-default btn-sm" href="/box/probality/set?boxid=<%= datas[i].box_id %>">中奖率设置</a>
                    <% } %>
                    <% if(session.permissionMap[1002]){ %>
                    <a class="btn btn-default btn-sm" href="/box/edit?boxid=<%= datas[i].box_id %>">编辑</a>
                    <% } %>
                    <% if(session.permissionMap[1001]){ %>
                    <a class="btn btn-danger btn-sm" href="/box_management/rembox?boxid=<%= datas[i].box_id %>"
                       onclick="return confirm('确定删除该箱子?')">删除</a>
                    <% } %>
                </td>
            </tr>
            <% } %>
            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript" src="/js/boxM.js"></script>
<script type="text/javascript">
    $(function () {
        //分页功能
        $('.twbsPagination').twbsPagination({
            totalPages: <%= pageCount %>,
            visiblePages: 10,
            href: '/box/list?num={{number}}'
        });
    })

    var looptimes = new Array();//循环时间
    var oncetimes = new Array();//执行一次的时间
    var count = 1;
    var loopcount = 0;//记录数组下标
    var oncecount = 0;
    var boxid = '';

    /**
     * 打开模态框
     * @param boxid
     */
    function openModal(box_id) {
        boxid = box_id;
        $('#myModal').modal('toggle');

    }

    $(function () {

        $('#datetimepicker3').datetimepicker({
            maskInput: true,
            pickDate: false
        });
        var picker = $('#datetimepicker3').data('datetimepicker');

        $('#datetimepicker2').datetimepicker({
            maskInput: true,
            format: 'yyyy/MM/dd hh:mm:ss',
            language: 'zh-CN'
        });


        var picker1 = $('#datetimepicker3').data('datetimepicker');
        $('#addLoop').click(function () {
            var date = picker.getLocalDate();
            var times1 = $('#times1').val();
            var duration1 = $('#duration1').val();//持续时间
            looptimes.push(times1 + '~' + duration1);
            console.log(date.toString() + '~~~~~~~~' + times1);
            $('#timesGroup').append('<button type="button" class="btn btn-default" id="alarms' + count + '"' +
                    ' style="margin: 8px 3px 0 0;" onclick="delalarm(' + count + ',' + loopcount + ')">' + times1 + ' [' + duration1 + '分钟]</button>');
            count++;
            loopcount++;
        });
        $('#addOnce').click(function () {
            var date = picker1.getLocalDate();
            var times2 = $('#times2').val();
            console.log(date.toString());
            var duration2 = $('#duration2').val();//持续时间
            oncetimes.push(times2 + '~' + duration2);

            $('#timesGroup').append('<button type="button" class="btn btn-default"  id="alarms' + count + '"' +
                    ' style="margin: 8px 3px 0 0;" onclick="delalarm1(' + count + ',' + oncecount + ')">' + times2 + ' [' + duration2 + '分钟]</button>');
            count++;
            oncecount++;
        });

        $('#submit').click(function () {
            var newTimeArr = looptimes.concat(oncetimes).join(',');
            var probability = $('#probability').val();
            $.post('/box/probality/set', {
                boxid: boxid,
                newTimeArr: newTimeArr,
                probability: probability
            }, function (result) {
                alert(result.msg);
            });
        });
    });
    function delalarm(count, loopcount) {
        $('#alarms' + count).remove();
        looptimes.splice(loopcount, 1);
    }
    function delalarm1(count, oncecount) {
        $('#alarms' + count).remove();
        oncetimes.splice(oncecount, 1)
    }

</script>